package com.xcf.center.client;

import com.xcf.center.ServerMeta;

import java.net.BindException;
import java.util.List;
import java.util.Random;

public class DefaultBalance implements IBalanceHandler<ServerMeta> {

    @Override
    public ServerWrapper<ServerMeta> balance(List<ServerWrapper<ServerMeta>> serverList) {
        int minIndex = 0;
        Long minValue = Long.MAX_VALUE;
        for (int i = 0; i < serverList.size(); i++) {
            Long requestNum = serverList.get(i).getRequestNum();
            if (requestNum < minValue) {
                minIndex = i;
                minValue = requestNum;
            }
        }
        return serverList.get(minIndex);
    }
}
